<?php

namespace app\api\Service;

use think\Db;
use app\common\library\Auth;

class CooperateService
{
    // 获取合作专区图片
    public static function getCooperate()
    {
        $details = \app\admin\model\Cooperate::where(['id'=>'1'])->value('image');
        return ['code'=>1,'msg'=>'查询成功','data'=>['details'=>$details]];
    }

    // 申请合作
    public static function applyCooperate($data)
    {
        try{
            if(!$data['name']) return ['code'=>0, 'msg'=>'请填写姓名','data'=>''];
            if(!$data['mobile']) return ['code'=>0, 'msg'=>'请填写手机号','data'=>''];
            if(!$data['area']) return ['code'=>0, 'msg'=>'请填写地区','data'=>''];

            $params = [
                'name' => $data['name'],
                'mobile' => $data['mobile'],
                'area' => $data['area'],
            ];

            $result = \app\admin\model\Cooperate::create($params);
            Db::commit();
        }catch(\Exception $e){
            Db::rollback();
            return ['code'=>0,'message'=>$e->getMessage(),'data'=>''];
        }
        if($result){
            return ['code'=>1,'msg'=>'操作成功','data'=>''];
        }else{
            return ['code'=>0,'msg'=>'操作失败','data'=>''];
        }
    }
}